//
//  WYRTabBarController.m
//  彩票项目
//
//  Created by 伍银荣 on 2021/7/20.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "WYRTabBarController.h"
#import "WYRNavController.h"
#import "HallViewCOntroller.h"

@interface WYRTabBarController ()

@end

@implementation WYRTabBarController

+(void)initialize {
    //[UIColor colorWithRed:243 / 255.0 green:232 / 255.0  blue:66 / 255.0 alpha:1.0]
    [super initialize];
    UITabBarItem *tbItem = [UITabBarItem appearance];
    [tbItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor] } forState:UIControlStateNormal];
    [tbItem setTitleTextAttributes:@{NSForegroundColorAttributeName:kRGBColor(243, 232, 66)} forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[UITabBar appearance] setBarTintColor: [UIColor blackColor]];
    [UITabBar appearance].translucent = NO;
    
    //设置tabBarController的子控制器
    //购彩大厅
   // UIViewController *vc1 = [self loadSubViewControllerWithSBName:@"Hall"];
    HallViewController *hallVC = [self loadSubViewControllerWithSBName:@"Hall" andItemTitle:@"购彩大厅" andNormalImgName:@"hall_nor" andSelectedImgName:@"hall_sel"];
   // HallViewController *hallVC = [self loadSubViewController:[HallViewController new] andSBName:@"Hall" andItemTitle:@"购彩大厅" andNormalImgName:@"goucaidating_sel" andSelectedImgName:@""];
    //竞技场
//    UIViewController *vc2 = [self loadSubViewControllerWithSBName:@"Arena"];
    
    UIViewController *vc2 = [self loadSubViewControllerWithSBName:@"Arena" andItemTitle:@"竞技场" andNormalImgName:@"jingjichang" andSelectedImgName:@"jingjichang-sel"];
    
//
//    //发现
//    UIViewController *vc3 = [self loadSubViewControllerWithSBName:@"Discovery"];
    
    UIViewController *vc3 = [self loadSubViewControllerWithSBName:@"Discovery" andItemTitle:@"发现" andNormalImgName:@"faxian" andSelectedImgName:@"faxian_sel"];
    
//    //开奖信息
//    UIViewController *vc4 = [self loadSubViewControllerWithSBName:@"History"];
     UIViewController *vc4 = [self loadSubViewControllerWithSBName:@"History" andItemTitle:@"开奖信息" andNormalImgName:@"kaijiang" andSelectedImgName:@"kaijiang-sel"];
//    //我的彩票
//    UIViewController *vc5 = [self loadSubViewControllerWithSBName:@"MyLottery"];
     UIViewController *vc5 = [self loadSubViewControllerWithSBName:@"MyLottery" andItemTitle:@"我的彩票" andNormalImgName:@"wode" andSelectedImgName:@"wode_sel"];
    
  //  self.viewControllers = @[vc1, vc2, vc3, vc4, vc5];
    self.viewControllers = @[hallVC, vc2, vc3, vc4, vc5];
    
    
    
    
    
//    //自定义tabBar
//
//    WYRTabBar *tabBar = [[WYRTabBar alloc]init];
//    tabBar.backgroundColor = [UIColor yellowColor];
//    //设置tabBar的frame为系统的frame
//    tabBar.frame = self.tabBar.frame;
//    [self.view addSubview:tabBar];
//    NSLog(@"frame = %@",NSStringFromCGRect(tabBar.frame));
//
//
//    for (int i = 0; i < self.viewControllers.count; i++) {
//        UIButton *tabBarBtn = [[UIButton alloc]init];
//        tabBarBtn.backgroundColor = [UIColor redColor];
//        CGFloat w = kScreenWidth / self.viewControllers.count;
//        CGFloat h = 60;
//        CGFloat x = w * i;
//        CGFloat y = 0;
    
//        tabBarBtn.frame = CGRectMake(x, y, w, h);
//        [tabBarBtn setImage:[UIImage imageNamed:@"-goucaidating-xuanzhong"] forState:UIControlStateNormal];
//        [tabBar addSubview:tabBarBtn];
 //   }
    
    
}

//根据storyBoard的名字返回storyBoard所指向的控制器

//- (UIViewController *)loadSubViewControllerWithSBName:(NSString *)name {
//    UIStoryboard *sb1 = [UIStoryboard storyboardWithName:name bundle:nil];
//    return [sb1 instantiateInitialViewController];
//}


- (UIViewController *)loadSubViewControllerWithSBName:(NSString *)name andItemTitle:(NSString *)title andNormalImgName:(NSString *)normalImgName andSelectedImgName:(NSString *)selectedImgName {
    UIStoryboard *sb1 = [UIStoryboard storyboardWithName:name bundle:nil];
    UIViewController *viewController = [sb1 instantiateInitialViewController];
    UIImage *normalImg = [UIImage imageNamed:normalImgName];
    UIImage *selectedImg = [UIImage imageNamed:selectedImgName];
    UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:title image:[normalImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[selectedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    //将自定义的UITabBarItem赋值给从storyBoard加载过来的控制器的tabBarItem
    viewController.tabBarItem = item;
    //设置导航栏的根控制器
//    WYRNavController *nav = [[WYRNavController alloc]initWithRootViewController:viewController];
//    [self addChildViewController:nav];
    //初始化storyBoard对象
    return viewController;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
